package com.smartlbs.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.smartlbs.baseframe.web.ResponseInfo;
import com.smartlbs.dto.BetInfoDto;
import com.smartlbs.entity.BetInfo;
import com.smartlbs.service.IBetInfoService;
import com.smartlbs.service.IUserOrderService;
import com.smartlbs.util.StringUtil;
import com.smartlbs.vo.BetInfoVo;
import com.smartlbs.vo.GameInfoVo;

/**
 * 押注信息控制层类
 * 
 * @author idaowei
 *
 */
@Controller
@RequestMapping("adminuser/betinfo")
public class SysBetInfonController {
	@Autowired
	private IBetInfoService betInfoService;

	
	@Autowired
	private IUserOrderService userOrderService;
	/**
	 * 修改、删除 押注信息,结算
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("updateBet")
	@ResponseBody
	public ResponseInfo updateBet(HttpServletRequest request) {
		int result = 0;
		String message = "";
		Object data = null;
		String betidstr = request.getParameter("betId");
		String lids = request.getParameter("lIds");
		try {
			if (betidstr != null) {
				BetInfo betInfo = new BetInfo();
				betInfo.setBetId(Long.valueOf(betidstr));
				betInfo.setlIds(lids);

				int update = betInfoService.update(betInfo);
				if (update > 0) {
					
				//	userOrderService.accountByBet(Long.valueOf(betidstr));
					
					result = 1;
					message = "修改成功";
				}
			} 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			message = "发生异常";

			e.printStackTrace();
		}

		ResponseInfo responseInfo = new ResponseInfo();
		responseInfo.setData(data);
		responseInfo.setResult(result);
		responseInfo.setMessage(message);
		return responseInfo;
	}

	/**
	 * 获取比赛押注项
	 * 
	 * @param request
	 * @param gameId
	 * @return
	 */
	@RequestMapping("getbetBygameId")
	@ResponseBody
	public ResponseInfo getbetBygameId(HttpServletRequest request, Long gameId) {
		int result = 0;
		String message = "";
		Object data = null;
		try {
			List<BetInfoVo> findbyGameId = betInfoService.findbyGameId(gameId);

			result = 1;
			message = "查询信息成功";
			data = findbyGameId;

		} catch (Exception e) {
			// TODO Auto-generated catch block
			message = "发生异常";

			e.printStackTrace();
		} finally {
		}
		ResponseInfo responseInfo = new ResponseInfo();
		responseInfo.setData(data);
		responseInfo.setResult(result);
		responseInfo.setMessage(message);
		return responseInfo;
	}

}
